home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / tsbgex / src / fish / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  5.3 KB  |  260 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h> 
  4. #include <winb.h>
  5. #include <te.h>
  6. #include <fntb.h>
  7. #include <gui.h>
  8. #include <egb.h>
  9. #include <guidbg.h>
  10. #include <file_dlg.h>
  11. #include "fish.h"
  12.  
  13. int aplid;
  14.  
  15. void main(int argc, char *argv[])
  16. {
  17.     MMICTRL ctrl;
  18.     extern int APL_init();
  19.  
  20.     ctrl.displayPage = SCREENAVAILABLE;
  21.     ctrl.mode = SCREENAVAILABLE;
  22.     ctrl.page0 = SCREENIGNORE;
  23.     ctrl.page1 = SCREENIGNORE;
  24.     ctrl.size = 0;
  25.     ctrl.ptr = NULL;
  26.     ctrl.asize = 0;
  27.     ctrl.aptr = NULL;
  28.     ctrl.white = 15;
  29.     ctrl.black = 8;
  30.     ctrl.gray = 7;
  31.     ctrl.xor = 7;
  32.     
  33.     if (MMI_Open(&ctrl) != NOERR){
  34.         MMI_Close();
  35.         return;
  36.     }
  37.     if (APL_init(argc, argv) != NOERR){
  38.         MMI_Close();
  39.         return;
  40.     }
  41.     MMI_ExecSystem();
  42.     MMI_Close();
  43. }
  44.  
  45. int task_mode = 0x03;
  46. int do_unmap = FALSE;
  47.  
  48. APL_init(int argc, char **argv)
  49. {
  50.     extern int timer;
  51.     extern int ypos1, ypos2;
  52.     extern int userFunc();
  53.     extern void fishmain(), fish_init();
  54.     extern void active_check();
  55.  
  56.     while (--argc > 0){
  57.         argv++;
  58.         if (strcmp(*argv, "-t") == 0  &&  argc > 1){
  59.             timer = atoi(*++argv);
  60.             argc--;
  61.         } else if (strcmp(*argv, "-m") == 0  &&  argc > 1){
  62.             task_mode = atoi(*++argv);
  63.             argc--;
  64.         } else if (strcmp(*argv, "-unmap") == 0){
  65.             do_unmap = TRUE;
  66.         } else if (strcmp(*argv, "-y1") == 0  &&  argc > 1){
  67.             ypos1 = atoi(*++argv);
  68.             argc--;
  69.         } else if (strcmp(*argv, "-y2") == 0  &&  argc > 1){
  70.             ypos2 = atoi(*++argv);
  71.             argc--;
  72.         }
  73.     }
  74.     aplid = MMI_GetApliId();
  75.     fish_init();
  76.     active_check(TRUE);
  77.     MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
  78.     MMI_CallMessage(aplid, GM_TITLE, (int)"おさかな", 0);
  79.     if (task_mode & 0x01)
  80.         MMI_SetIdleTaskFunc(fishmain);
  81.     if (task_mode & 0x02)
  82.         MMI_SetIntervalFunc(fishmain);
  83.     MMI_CallMessage(aplid, GM_SLEEP, 0, 0);
  84.     return (NOERR);
  85. }
  86.  
  87. int (**winfunc)();
  88.  
  89. connect_server()
  90. {
  91.     int server;
  92.  
  93.     if ((server = MMI_CallMessage(aplid, GM_QUERYID, QM_SAMEAS, (int)SERVER))
  94.                 > NOERR){
  95.         if (MMI_CallMessage(server, GM_EXECUSER, 0, 0) != MAGIC)
  96.             server = NOERR; /* not ready */
  97.         else
  98.             winfunc = (int (**)())MMI_CallMessage(server, GM_EXECUSER, 1, 0);
  99. #ifdef DEBUG
  100.         printf("FISH: server = %d, winfunc = 0x%x\n", server, winfunc);
  101. #endif
  102.     } else {
  103. #ifdef DEBUG
  104.         printf("FISH: server = %d\n", server);
  105. #endif
  106.         server = NOERR;
  107.     }
  108.     return (server);
  109. }
  110.  
  111. int server = NOERR;
  112. int server_die = FALSE;
  113. int own = FALSE;
  114. int active = FALSE;
  115. int restart = TRUE;
  116. int unmapped = FALSE;
  117. short vramseg;
  118. u_long vramoff;
  119. int pixel, fbwidth, vwidth, vheight, dwidth;
  120. RESOLUTION mode = { 0, 0, 0, 0, 0, 0, };
  121.  
  122. void active_check(int init)
  123. {
  124.     int owner;
  125.     char *title;
  126.     SCRNDATA screen;
  127.     extern int fish_first, fish_count;
  128.     extern int modecmp();
  129.     extern void setup();
  130.     
  131.     if (server == NOERR){
  132.         if ((server = connect_server()) > NOERR){
  133.             init = TRUE;
  134.             restart = TRUE;
  135.             fish_first = TRUE;
  136.             fish_count = 1;
  137.         }
  138.     }
  139.     if (server <= NOERR){
  140.         server = NOERR;
  141.         restart = TRUE;
  142.         fish_count = 1;
  143.         return;
  144.     }
  145.     owner = MMI_CallMessage(aplid, GM_QUERYID, QM_BACKPAGE, 0);
  146.     title = (char *)MMI_CallMessage(owner, GM_TITLE, (int)NULL, 0);
  147. #ifdef DEBUG
  148.     printf("FISH: BACKPAGE owner is %s\n", title);
  149. #endif
  150.     MMI_CallMessage(owner, GM_SCRNDATA, FALSE, (int)&screen);
  151.     if (init){
  152.         if (strcmp(title, OWNER) == 0){
  153.             own = TRUE;
  154.             mode = screen.page[1];
  155.             setup(&screen.page[1]);
  156.         } else {
  157.             own = active = FALSE;
  158.         }
  159.         return;
  160.     }
  161.     if (own){
  162.         if (strcmp(title, OWNER) == 0){
  163.             if (modecmp(&mode, &screen.page[1]) != 0){
  164. #ifdef DEBUG
  165.                 printf("FISH: mode change\n");
  166. #endif
  167.                 mode = screen.page[1];
  168.                 setup(&screen.page[1]);
  169.             }
  170.         } else {
  171.             own = active = FALSE;
  172.         }
  173.     } else {
  174.         if (strcmp(title, OWNER) == 0){
  175.             own = TRUE;
  176.             setup(&mode);
  177.         }
  178.     }
  179. #ifdef DEBUG
  180.     printf("FISH: own=%d, active=%d, restart=%d\n", own, active, restart);
  181.     printf("FISH: %d %d %d %d %d 0x%x 0x%x\n", pixel, fbwidth, vwidth, dwidth, vheight, vramseg, vramoff);
  182. #endif
  183. }
  184.  
  185. void setup(RESOLUTION *page1)
  186. {
  187.     extern int fish_count;
  188.     
  189.     restart = TRUE;
  190.     fish_count = 1;
  191.     pixel = page1->pixel;
  192.     fbwidth = page1->byte;
  193.     vwidth = page1->vx;
  194.     dwidth = page1->dx;
  195.     vheight = page1->vy;
  196.     vramseg = page1->segment;
  197.     vramoff = (u_long)page1->offset;
  198.     active = (pixel == 4  ||  pixel == 16);
  199.     unmapped = FALSE;
  200. }
  201.  
  202. modecmp(RESOLUTION *a, RESOLUTION *b)
  203. {
  204.     return (memcmp(a, b, sizeof (RESOLUTION) - sizeof (short)));
  205. }
  206.  
  207. userFunc(int apliId, int messId, int info, int data)
  208. {
  209.     int ret;
  210.     extern int fish_count;
  211.     extern void terminate(), map();
  212.  
  213.     ret = ILLEGAL_FUNCTION ;
  214.  
  215.     switch (messId){
  216.         case GM_EXECUSER:    /* server die */
  217. #ifdef DEBUG
  218.             printf("FISH: server die\n");
  219. #endif
  220.             server_die = TRUE;
  221.             server = NOERR;
  222.             own = active = FALSE;
  223.             terminate();
  224.             break;
  225.         case GM_PRESCRCHG: 
  226. #ifdef DEBUG
  227.             printf("FISH: PRESCRCHG\n");
  228. #endif
  229.             if (!server_die  &&  do_unmap){
  230.                 map(FALSE);    
  231.                 fish_count = 1;
  232.             }
  233.             ret = NOERR;
  234.             break;
  235.         case GM_POSTSCRCHG:
  236. #ifdef DEBUG
  237.             printf("FISH: POSTSCRCHG\n");
  238. #endif
  239.             if (server_die)
  240.                 server_die = FALSE;
  241.             else
  242.                 active_check(FALSE);
  243.             ret = NOERR;
  244.             break;
  245.         case GM_QUIT:
  246.             terminate();
  247.             MMI_SetHaltFlag(TRUE);
  248.             ret = NOERR;
  249.             break;
  250.         case GM_PURGE:
  251.         case GM_ENVIRONMENT:
  252.         case GM_ERASE: 
  253.         case GM_SHOW:
  254.         case GM_UPDATE:
  255.             ret = NOERR;
  256.             break;
  257.     }
  258.     return (ret);
  259. }
  260.